package com.itheima.aspact;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Component
@Aspect
@Slf4j
public class RecordTimeAspect {
    //@Around("execution(* com.itheima.service.impl.*.save(..))")
    @Around("@annotation(com.itheima.aspact.RecordTimeAnno)")
    public Object abc(ProceedingJoinPoint pjp) throws Throwable {
        log.info("---------011111111.");
        long start = System.currentTimeMillis();

        Object result = null;
        try {
            result = pjp.proceed();
        } catch (Throwable e) {
            throw new RuntimeException(e);
        }

        long end = System.currentTimeMillis();

        log.info("Time taken: {} ms", end - start);

        log.info("---------------22222222.");
        return result;
    }
//    @Around("execution(* com.itheima.service.impl.StudentServiceImpl.*(..))")
//    public Object acd(ProceedingJoinPoint pjp) throws Throwable {
//        long start = System.currentTimeMillis();
//        Object result = pjp.proceed();
//        long end = System.currentTimeMillis();
//        log.info("Time taken: {} ms", end - start);
//        return result;
//    }


}

